package com.chris.libs.base.x.mvpp.recycler;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.chris.libs.base.x.mvpp.activity.BaseActivity;
import com.chris.libs.base.x.mvpp.callbacks.BaseRecyclerView;

import butterknife.ButterKnife;

/**
 * Created by Chris Chen on 2017/7/3 17:19.
 * Explain:RecyclerView.ViewHolder的封装基类，依赖于Butterknife
 */

public abstract class BaseRecyclerHolder<D> extends RecyclerView.ViewHolder {
    protected View itemView;
    protected Context context;
    protected BaseRecyclerView.OnItemClickListener<D> onItemClickListener;

    public BaseRecyclerHolder(Context context, View itemView) {
        super(itemView);
        this.context = context;
        this.itemView = itemView;
        ButterKnife.bind(this, itemView);
    }

    public BaseRecyclerHolder(Context context, View itemView, BaseRecyclerView.OnItemClickListener<D> onItemClickListener) {
        this(context, itemView);
        this.onItemClickListener = onItemClickListener;
    }

    public View getItemView() {
        return itemView;
    }

    /**
     * 内部处理刷新
     */
    public void refresh() {
    }

    /**
     * 更新视图
     *
     * @param item
     */
    public abstract void refreshView(D item);

    /**
     * 更新视图
     * 带着集合元素下标
     *
     * @param item
     * @param position
     */
    public void refreshView(D item, int position) {
    }

    /**
     * 更新视图
     * 带着集合元素下标和BaseActivity
     * 用于列表项目控件内部控件处理跳转
     *
     * @param baseActivity
     * @param item
     * @param position
     */
    public void refreshView(BaseActivity baseActivity, D item, int position) {
    }

    public void showMessage(CharSequence message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
}
